﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Collections.ObjectModel;
using bus = WpfDataBingding.TaskServiceReference;

namespace WpfDataBingding.DevTreeData
{
    /// <summary>
    /// 设备类型集合
    /// </summary>
    public class DevTypeCollection
    {
        ObservableCollection<DevType> devTypeList;

        public ObservableCollection<DevType> DevTypeList
        {
            get { return devTypeList; }
            set { devTypeList = value; }
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        public DevTypeCollection()
        {
            
        }

        /// <summary>
        /// 将数据总线获取设备类型数组转换为本地绑定控件的设备类型
        /// </summary>
        /// <param name="deviceTypeArray">数据总线获取设备类型数组</param>
        public void initFromDataBusDevTypeArray(bus.DeviceType[] deviceTypeArray)
        {
            //bus.DataBusServiceClient d = new WpfDataBingding.TaskServiceReference.DataBusServiceClient();
            //d.QueryAllDeviceTypeInfo();
            devTypeList = new ObservableCollection<DevType>();

            for (int i = 0; i < deviceTypeArray.Length; i++)
            {
                DevType devType_new = new DevType();
                devType_new.TypeName = deviceTypeArray[i].DevTypeName;
                devType_new.IconName = "dev"+(i+1)+".jpg";/////debug
                deviceTypeArray[i].DevTypeIconName = devType_new.IconName;/////debug
                devTypeList.Add(devType_new);
            }
        }

        /// <summary>
        /// 根据设备类型名返回设备类型对象
        /// </summary>
        /// <param name="devTypeName"></param>
        /// <returns></returns>
        public DevType getDevTypeByName(string devTypeName)
        {
            foreach (DevType dt in DevTypeList)
            {
                if (dt.TypeName == devTypeName)
                    return dt;
            }
            return null;
        }

    }
}
